package com.itheima.app.manager.umsManager;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.itheima.app.exception.BusinessException;
import com.itheima.commons.Code;
import com.itheima.commons.R;
import com.itheima.domain.db.ums.UmsResourceCategory;
import com.itheima.service.umsService.UmsResourceCategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UmsResourceCategoryManager {

    @DubboReference
    private UmsResourceCategoryService umsResourceCategoryService;

    /**
     * 增加后台资源分类
     *
     * @param umsResourceCategory
     * @return
     */
    public R addResourceCategory(UmsResourceCategory umsResourceCategory) {
        umsResourceCategoryService.addResourceCategory(umsResourceCategory);
        return new R(Code.SUCCESS, "新增资源分类成功");
    }

    /**
     * 删除资源分类
     *
     * @param id
     * @return
     */
    public R deleteResourceCategory(Integer id) {
        if (ObjectUtils.isEmpty(id)) {
            throw new BusinessException("id为空");
        }
        umsResourceCategoryService.deleteResourceCategory(id);
        return new R(Code.SUCCESS, "删除成功");
    }


    /**
     * 修改资源分类
     *
     * @param id
     * @param umsResourceCategory
     * @return
     */
    public R updateResourceCategory(Integer id, UmsResourceCategory umsResourceCategory) {
        if (ObjectUtils.isEmpty(id)) {
            throw new BusinessException("id为空");
        }
        umsResourceCategoryService.updateResourceCategory(id, umsResourceCategory);
        return new R(Code.SUCCESS, "修改成功");
    }


    /**
     * 查询所有资源分类
     *
     * @return
     */
    public List<UmsResourceCategory> selectResourceCategoryList() {
        List<UmsResourceCategory> umsResourceCategories = umsResourceCategoryService.selectResourceCategoryList();
        return umsResourceCategories;
    }
}
